package edu.hrbeu.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author wzq
 * @create 2022-01-07-0:35
 */
@RestController
public class RibbonController {
    @Autowired
    RestTemplate restTemplate;

    @RequestMapping({"/","/index"})
    @HystrixCommand(fallbackMethod = "invokeError")
    public String invoke(){
        String ret = restTemplate.getForObject("http://service-lucy/index", String.class);
        return "ribbon,"+ret;
    }

    public String invokeError(){
        return "Ribbon,您访问的服务出现错误,请稍后重试!";
    }
}
